// TCP handling

#ifndef TCP_H
#define TCP_H

#include "eth.h"
#include "pack.h"

// tcp flags type
struct tcpFlags {
	unsigned int FIN : 1;
	unsigned int SYN : 1;
	unsigned int RST : 1;
	unsigned int PSH : 1;
	unsigned int ACK : 1;
	unsigned int URG : 1;
	unsigned int ECE : 1;
	unsigned int CWR : 1;
} __attribute__((packed));

// tcp flags type
typedef struct tcpFlags tcpFlags;

// tcp packet type
struct tcpPacket {
	unsigned short sourcePort;
	unsigned short destPort;
	unsigned int seqNum;
	unsigned int ackNum;
	unsigned int reserved : 4; /** other way around, it's network order **/
	unsigned int dataOffset : 4;
	tcpFlags packFlags;
//	unsigned char packFlags;
	unsigned short WindowSize;
	unsigned short Checksum;
	unsigned short UrgPtr;
	unsigned char* packData;
} __attribute__((packed));

// easier to type
typedef struct tcpPacket tcpPacket;

// handles a tcp packet
void handleTCPpacket(ethernet_t *eth, packet_t *p);

#endif
